<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateRole extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table("role",['comment'=>'角色','engine'=>'Innodb','collation'=>'utf8mb4_general_ci']);
        // 表必备字段
        $table->addColumn(Column::string('uuid')->setLimit(32)->setComment('唯一编号'));
        // 业务字段
        $table->addColumn(Column::string('name')->setLimit(20)->setComment('角色名称'));
        $table->addColumn(Column::json('rules')->setComment('权限key'));
        $table->addColumn(Column::integer('client')->setLimit(11)->setComment('用户端'));
        // 表必备字段
        $table->addColumn(Column::integer('creator')->setLimit(11)->setComment('创建者id'));
        $table->addColumn(Column::integer('updater')->setLimit(11)->setComment('更新者id'));
        $table->addColumn(Column::integer('create_time')->setDefault(0)->setUnsigned()->setComment('创建时间'));
        $table->addColumn(Column::integer('update_time')->setDefault(0)->setUnsigned()->setComment('修改时间'));
        $table->addColumn(Column::integer('delete_time')->setDefault(0)->setUnsigned()->setComment('软删除的时间'));
        // 创建数据库表
        $table->create();
    }
}
